﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class UpdatePass : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—安全保密设置：密码更改   {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_name"] != null)
                {
                    this.lbl_title.Text = " " + Session["enterprise_name"].ToString();
                }
                if (Session["enterprise_bid"] == null)
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");

                }
            }


        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (Session["enterprise_bid"] != null)
            {
                int bid = Convert.ToInt32(Session["enterprise_bid"]);

                string oldpass = this.txt_oldpass.Text;
                string newpass = this.txt_newpass.Text;
                string confirm = this.txt_confirm.Text;
                oldpass = myPublic.GetMd5(oldpass);
                newpass = myPublic.GetMd5(newpass);

                lcmyjobs.BLL.enterprise_basic eb = new BLL.enterprise_basic();

                DataSet ds = eb.GetList(" enterprise_bid=" + bid);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["pwd"].ToString() == oldpass)
                    {
                        if (eb.UpdatePwd(bid, newpass))
                        {
                            Maticsoft.Common.MessageBox.Show(this, "修改成功！");
                        }
                        else
                        {
                            Maticsoft.Common.MessageBox.Show(this, "修改失败！");
                        }
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "旧密码不正确！");
                    }
                }

            }
        }
    }
}